    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package FrontEnd;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author brandonL
 */
public class FEMessageHandler extends Thread {

    private Socket RMSocket = null;
    private ObjectInputStream RMin;
    private ObjectOutputStream RMout;
    
    private Vector<Socket> RMSockets = null;
    private Vector<ObjectOutputStream> RMOutputs =null;
    private Vector<ObjectInputStream> RMInputs = null;
    
    private String request;
    public String Response="";
    
    public FEMessageHandler(Socket rmSocket, String request, ObjectInputStream RMInput, ObjectOutputStream RMOutput, Vector<Socket> rmSockets, Vector<ObjectInputStream> RMInputs, Vector<ObjectOutputStream> RMOutputs)
    {
        this.RMSocket = rmSocket;
        this.RMin = RMInput;
        this.RMout = RMOutput;
        this.request = request; 
        
        this.RMSockets = rmSockets;
        this.RMInputs = RMInputs;
        this.RMOutputs = RMOutputs;
        
        this.start();
    }
    @Override
    public void run()
    {
        
        try 
        {
            
            RMout.writeObject(this.request);
            this.Response = (String)RMin.readObject();
             
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(FEMessageHandler.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IOException ex) {
            this.RMSockets.remove(this.RMSocket);
            this.RMInputs.remove(this.RMin);
            this.RMOutputs.remove(this.RMout);
            //FEServer.ToRemove.add(RMSocket);
            
            this.Response="CRASHED&&&";
            Logger.getLogger(FEMessageHandler.class.getName()).log(Level.SEVERE, null, ex);
        }        
        
        
        
    }
}

